package net.caixiaomi.info.ui.discovery;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import net.caixiaomi.info.R;
import net.caixiaomi.info.adapter.LeagueHotAdapter;
import net.caixiaomi.info.base.BaseFragment;
import net.caixiaomi.info.base.quickadapter.BaseQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.interfaces.ComonFragmentImpl;
import net.caixiaomi.info.model.LeagueDetailShooterInfo;
import net.caixiaomi.info.model.LeagueDetailShooterListEntity;
import net.caixiaomi.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by mac on 2018/9/11.
 */

public class LeagueShooterFragment extends BaseFragment implements ComonFragmentImpl {

    private LeagueDetailShooterListEntity entity;

    @BindView(android.R.id.list)
    RecyclerView mListView;

    @BindView(R.id.no_data_tv)
    TextView mNoData;

    private LeagueShooterAdapter mAdapter;

    @Override
    protected int fragmentLayout() {
        return R.layout.league_shooter_layout;
    }

    public void initData(LeagueDetailShooterListEntity entity){
        this.entity=entity;
        List<LeagueDetailShooterInfo> leagueShooterInfoList=entity.getLeagueShooterInfoList();
        if(leagueShooterInfoList.size()==0){
            mNoData.setVisibility(View.VISIBLE);
            mListView.setVisibility(View.GONE);
            return;
        }
        List<MultiItemEntity>list=new ArrayList<>();
        list.addAll(leagueShooterInfoList);
        mAdapter.setNewData(list);

    }

    @Override
    protected void onFragmentCreated(View view, @Nullable Bundle savedInstanceState) {
        mListView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new LeagueShooterAdapter(R.layout.league_shooter_item);
        mListView.setAdapter(mAdapter);
        View headerView=View.inflate(getActivity(),R.layout.league_shooter_item,null);
        LinearLayout group=headerView.findViewById(R.id.league_shooter_group);
        group.setBackgroundResource(R.color.shadow);
        mAdapter.addHeaderView(headerView);
    }

    @Override
    public void setType(int type) {

    }

    @Override
    public void setFilter(String filter) {

    }

    public class LeagueShooterAdapter extends BaseQuickAdapter<MultiItemEntity, BaseViewHolder> {

        public LeagueShooterAdapter(int layoutResId) {
            super(layoutResId);
        }

        @Override
        protected void convert(BaseViewHolder helper, MultiItemEntity item) {
            LeagueDetailShooterInfo entity= (LeagueDetailShooterInfo) item;
            helper.setText(R.id.league_shooter_name0,entity.getSort()+"");
            helper.setText(R.id.league_shooter_name1,entity.getPlayerName()+"");
            helper.setText(R.id.league_shooter_name2,entity.getPlayerTeam()+"");
            helper.setText(R.id.league_shooter_name3,entity.getInNum()+"");
        }
    }
}
